package com.alex.controller.api;

import com.alex.service.BookService;
import com.alex.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
public class UserRestAPI {

    @Resource
    private UserService userService;

//    @RequestMapping(value = "/api/rest/user/query/{username}",  produces = "text/html;charset=UTF-8")
    @RequestMapping(value = "/api/rest/user/query/{username}")
    public Object checkUsername(@PathVariable("username") String username) {
        System.out.println("check username: " + username);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("result", false);
        if (userService.nameIsExist(username)) {
            map.put("result", true);
            return map;
        }
        return map;
    }

    @RequestMapping(value = "/api/rest/user/query/all")
    public Object getAll() {
        return userService.getAll();
    }

    @RequestMapping(value = "/api/rest/user/query/test01")
    public Object test01() {
        return "test中文";
    }

    @RequestMapping(value = "/api/rest/user/query/test02")
    public Object test02() {
        return userService.getById(4);
    }

    @RequestMapping(value = "/api/rest/user/query/test03")
    public Object test03() {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("result", "林雪阳");
        return map;
    }
}
